<!DOCTYPE html>
<html>
<head>
<head/>
<div th:include="base-libs :: base-libs" />
<!-- <div th:include="common/fwb-modal :: fwb-modal" />
<div th:include="common/xypl-modal :: xypl-modal" />
<div th:include="common/zj-modal :: zj-modal" />
<div th:include="common/bgfwbpl-modal :: bgfwbpl-modal" />
<div th:include="common/common-export :: common-export" /> -->


<!-- <link th:href="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.css'" rel="stylesheet"/>
<script th:src="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.js'"></script>
<link rel="stylesheet" th:href="${appName} + 'css/bootstrap-select.min.css'"/>	
<script th:src="${appName} + 'js/bootstrap-select.min.js'"></script>		 		 
<script th:src="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table-zh-CN.min.js'"></script> -->
<script th:src="@{/service/js/jtqy.js}"></script>
	 		 
<title>正式签约</title>
<style type="text/css">
body{
	padding: 0px 0px;
}
.table>tbody>tr>td{
	vertical-align: middle!important;
    text-align: center!important;
}
.spanBtn{
	font-weight: bold;
	color: blue;
	cursor:pointer;
}

.form-table select {
    width: 100%;
}
.timeLeft{
	width:36% !important;
	border: 1px solid #B6B6B6;
}
.timeRight{
	width:36% !important;
	float:right;
	border: 1px solid #B6B6B6;
}
.timeSpan{
	display:inline-block;
	width:3%;
	text-align:right;
}
</style>
</head>
<script th:inline="javascript">
	/**读取request中的初始化数据*/
var data = [[${data}]];
</script>
<script type="text/javascript">
$(function() {
 	initDate();
 	initView();
 	queryForm();
});

/**
*
*/
function queryForm() {
	$("#dgForm").datagrid({"url":  contextRoot+"jtqy/queryPage.service" });
}
function queryHandler() {
	$("#dgForm").datagrid("load");
}
function colseOpenBackHandler(){
	var value = StoreCache.removeCache("JTQY_OPT_SUCCESS");
	if(!StringUtils.isEmpty(value)){
		queryReload();
	}
}
function queryReload(){
	$("#dgForm").datagrid("reload");
	//$("#dgForm").clearChecked();
}

function initDate(){
	$(".form-control").CacheForSelect();
	fwbDataSelectInit();
	var endTimeObj = {
			elem: '#QYJSSJ',
		  	choose: function(datas){
		  		startTimeObj.max = datas;
		    }
	};
	laydate(endTimeObj);
	//生效日期
	var startTimeObj = {
		 elem: '#QYKSSJ',
	  	 choose: function(datas){
	  		endTimeObj.min = datas;
	  	 }
	};
	laydate(startTimeObj);
}

function fwbDataSelectInit(){
	for(var i = 0; i < data.fwbAry.length ; i ++){
		var item = data.fwbAry[i];
		var option = $("<option>").val(item["FWBID"]).html(item["FWBMC"]);
		$("#FWBID").append(option);
	}
	for(var i = 0; i < data.tdAry.length ; i ++){
		var item = data.tdAry[i];
		var option = $("<option>").val(item["TDID"]).html(item["TDMC"]);
		$("#YLTDID").append(option);
	}
}

function initView()
{
	//回车查询
	enterToQuery(queryHandler);
	
	$("#dgForm").datagrid({
		idField : "QYXXID",
		striped : true,
		fit:true,
		fitColumns:true,
		columns : [[
			{
			    field: "checkStatus",
				checkbox: true
			}, 
			{
				field : "XM",
				title : "姓名"
				,width:13,
				align:'left'
			},
			{
				field : "ZJHM",
				title : "证件号码"
				,width:20
				,align:'left'
				,formatter: function(value,row){
					return formatIdcard(value);
				}
			},
			{
				field : "SJHM",
				title : "手机号码",
				align:'left',
				width:15
			},
			{
				field : "JTZZ",
				title : "家庭住址"
				,width:35
				,formatter: function(value,row){
					return formatTitle(value);
				}
			},
			{
				field : "QYSJ",
				title : "签约时间",
				align:'left',
				width:22,
				formatter: function(value){
//					if(!StringUtils.isEmpty(value)){
//						return value.substring(0,10);
//					}
					return value;
				}
			},
			{
				field : "RQFLMC",
				title : "人群分类"
				,width:20
				,formatter: function(value,row){
					return formatTitle(value);
				}
			},
			{
				field : "TDMC",
				title : "签约团队",
				width:15,
				align:'left',
				formatter: function(value,row){
					return formatTitle(value);
				}
			},
			{
				field : "FWBMC",
				title : "签约服务包"
				,width:25
				,formatter: function(value,row){
					return formatTitle(value);
				}
			},
			{
				field : "QYLX",
				title : "签约状态",
				width:12,
				align:'left',
				formatter : function(value, row, index) {
					row.QYZT = getQylx(value); //QYZT导出需要
					return row.QYZT;
				}
			},
			{
				field : "cz",
				title : "操作",
				width:7,
				align:'left',
				formatter : function(value, row, index){
					row = JSON.stringify(row).replace(/"/g, '&quot;');
                    return '<span class="spanBtn" onclick="operateFormatter(' + row + ')">详细</span>';
				}
			}
		]]
		,pagination : true
		,pageSize : 10
		,pageList: [10, 20, 50, 100, 200]
		,method : "post"
		//,url: contextRoot+"jtqy/"
		,onBeforeLoad: function(params){
		    if(StringUtils.isEmpty($("#YLTDID").val())) return false;
			params["ZJHM"] = $("#ZJHM").val();
			params["XM"] = $("#XM").val();
			params["RQFL"] = $("#RQFL").val();
			params["FWBID"] = $("#FWBID").val();
			params["YLTDID"] = $("#YLTDID").val();
			params["QYKSSJ"]=$("#QYKSSJ").val();
			params["QYJSSJ"]=$("#QYJSSJ").val();
			params["QYLX"] = "01";
			$("#dgForm").datagrid("clearChecked");
			return params;
		}
	
	});
	
	//解约
	$("#btnJy").on("click", function(){
		var selection = getCheckedRows();
		if(selection.length>0){
	    	var invalidArray = new Array();
		    $.each(selection, function(index, item)
			{ 
		    	if(item["SFXY"] == "1"){
		    		invalidArray.push(item["XM"]);
		    	}
			});
		    var xyry = "";
		    if(invalidArray.length>0){
		    	var xm = invalidArray.join(",");
		    	xyry = xm + "已续约，解约会作废续约记录，";
		    }
			parent.layer.confirm(xyry + '您确定要解约这' + selection.length + '个人吗？' , {icon: 3, title:'提示'}, function(index){
				  parent.layer.close(index);
				  parent.layer.prompt({title: '请填写解约原因', formType: 2}, function(text, index){
				    if(StringUtils.isEmpty(text)){
				    	parent.layer.msg('请填写解约原因！');
				    	return;
				    }
				    qyxxJyFun(text);
				    parent.layer.close(index);
				  });
				});
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	//解约更新
	function qyxxJyFun(jyyy){
		var selection = getCheckedRows();
		var qyxxidArray = new Array();
		 $.each(selection, function(index, item)
		{ 
		   qyxxidArray.push(item["QYXXID"]);
		});
		var param = {
			QYXXIDS:qyxxidArray.join(","),
			ZTMS:jyyy
		};
		var jyurl = $.QuickUrlUtils.getProjectName()+"/jtqy/jyfw.service"
		$.QuickRemote.AjaxJson(jyurl,function(result){
			if (result["state"]) {
			   $.QuickAlert.alertNormal("解约成功！",{callback: function(){
				   queryReload();
				}});
			} else {
				$.QuickAlert.alertFail({
					content : info["faultInfo"]
				});
			}
		},param);
	}

	//续约点击按钮事件
	$("#btnXy").on("click", function(){
		//alert("反人类设计，需要重新设计！");
		//return ;
		var selection = getCheckedRows();
		if(selection.length>0){
			var yxyry = [];
			$.each(selection,function(index,item){
				if(item.SFXY == "1"){
					yxyry.push(item.XM); 
				}
			});
			if(yxyry.length > 0){
				$.QuickAlert.alertFail({content : yxyry.join(",") + "近期已有续约记录！"});
				return ;
			}
			StoreCache.setCache("JTQYXYINFO", selection);
			parent.layer.open({
				type : 2,
				title : "续签",
				shadeClose : false,
				shade : 0.8,
				area : [ "90%", "80%" ],
				content: contextRoot + 'model/xyModel.html?YLJGID=' + parent.userInfo.PTJGID,
				end: colseOpenBackHandler
			}); 
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	
	//变更服务包
	$("#btnBgfwb").on("click", function(){
		var selection = getCheckedRows();
		if(selection.length>0){
			StoreCache.setCache("JTQYBGFWBINFO", selection);
			parent.layer.open({
				type : 2,
				title : "变更服务包操作",
				shadeClose : false,
				shade : 0.8,
				area : [ "90%", "80%" ],
				content: contextRoot + 'model/bgfwbModel.html?YLJGID=' + parent.userInfo.PTJGID,
				end: colseOpenBackHandler
			}); 
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	
	//
	//转介
	//转介信息确认
	$("#btnZj").on("click", function(){
		var selection = getCheckedRows();
		if(selection.length>0){
	    	var YLTDID = selection[0].YLTDID;
			var qyids = [];
			var fwbids = [];
	    	var count = 0;
		    $.each(selection, function(index, item)
			{ 
		    	qyids.push(item.QYXXID);
		    	fwbids.push(item.FWBID);
		    	if(item.YLTDID==YLTDID && item.QYLX == '01'){
		    		count ++ ;
		    	}
			});
	    	if(count==selection.length){
				parent.layer.open({
					type : 2,
					title : "转介申请",
					shadeClose : false,
					shade : 0.8,
					area : [ "320px", "335px" ],
					content: contextRoot + 'model/zjModel.html?TDZT=1&YLTDID=' + YLTDID + '&RS=' +  count + '&QYXXIDS=' + qyids.toString()
							+ '&FWBIDS=' + fwbids.join(";") + "&YLJGID=" + parent.userInfo.PTJGID,//iframe的url
					end: colseOpenBackHandler
					}); 
	    	}else{
		    	$.QuickAlert.alertFail({content : "您选中的居民，签约团队不一致或签约状态不符合，无法一起转介。请勾选签约团队相同的居民进行批量转介！"});
	    	}
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		} 
	});
	
	/** 打印协议 */
	$("#btnDy").click(function(){
		var selection = getCheckedRows();
		if(selection.length>0){
	    	var qyxxidArr = [];
	    	$.each(selection, function(i,item){
	    		qyxxidArr.push(item.QYXXID);
	    	})
	    	$("#QYXXIDS").val(qyxxidArr.join());
			$("#printForm")[0].submit();
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		} 
	})
	
	/**导出服务包*/
	$("#btnExport").on("click", function(){
		$("#exportForm").submit();
	});
	/** 获取已选中的记录  */
	function getCheckedRows(){
		var selection = $("#dgForm").datagrid("getChecked");
		return selection;
	}
}

/**获取签约状态*/
function getQylx(qylx) {
	if (qylx == "01") {
		qylx = "已签约";
	} else if (qylx == "02") {
		qylx = "转介中"
	} else if (qylx == "03") {
		qylx = "已解约";
	}
	else if (qylx == "04") {
		qylx = "已到期 ";
	}
	else if (qylx == "00") {
		qylx = "预签约 ";
	}

	return qylx;
}

/**操作格式化*/
function operateFormatter(value) {
	//console.log(value);
	StoreCache.setCache("BACKINFO", contextRoot + "jtqy/index.html");
	StoreCache.setCache("JTQYXQINFO", value);
	location = "detail.html?to=detail&JMXXID=" + value.JMXXID;
}

function doTimeTask(){
    $.QuickRemote.AjaxJson(contextRoot + "jtqyTimeTask/updateQylxByTimedask", function(result){
//		alert(JSON.stringify(result));
	}, null);
}
</script>
<body class="easyui-layout" fit="true" border="false">
	<div region="north" style="border: none; overflow: hidden; background-color: #f9f9f9;">
		<div style="width: 100%; margin-left: 30px">
			<h3 style="text-align:center;line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;">正式签约列表</h3>
		</div>
			
			<!-- 打印 -->
			<form id="printForm" action="printXy.service" enctype="multipart/form-data" style="display:none">
				<input name="QYXXIDS" id="QYXXIDS" type="hidden">
			</form>
			
			<!-- 导出 -->
			<form id="exportForm" action="export.service" enctype="multipart/form-data">
				<table class="form-table">
					<tr>
						<td class="td-text">姓名：</td>
						<td class="td-content">
							<input id="XM" name="XM" class="form-control dataField" type="text" style="width: 100%;"
								>
						</td>
						<td class="td-text">证件号码：</td>
						<td class="td-content">
							<div style="display: inline;">
								<input id="ZJHM" name="ZJHM" class="form-control dataField"  style="width: 100%;"/>
							</div>
						</td>
						<td class="td-text">人群分类：</td>
						<td class="td-content">
							<select id="RQFL" name="RQFL" class="form-control" quick-config="label:'人群分类', tableName:'TB_ZY_RQFL' " >
							</select>
						</td>
						<td class="td-text" style="text-align:center;width:150px;">
							<button id="btnQuery" class="btn btn-info" type="button" id="btnQueryFwb" onclick="queryHandler()">查询</button>
							<button id="btnExport" class="btn btn-info" type="button">导出</button>
						</td>
					</tr>
					<tr>
						<td class="td-text">签约时间：</td>
						<td class="td-content">
							 <input id="QYKSSJ" name="QYKSSJ" style="height:30px;" class="input-text laydate-icon dataField timeLeft" />
							 <span class="timeSpan">-</span>
							<input id="QYJSSJ" name="QYJSSJ" style="height:30px;" class="input-text laydate-icon dataField timeRight" />
						</td>
						<td class="td-text">签约团队：</td>
						<td class="td-content">
							<select id="YLTDID" name="YLTDID" class="form-control">
							</select>
						</td>
						<td class="td-text">服务包：</td>
						<td class="td-content">
							<select id="FWBID" name="FWBID" class="form-control">
								<option value="">请选择</option>
							</select>
						</td>
						<td class="td-text">
						</td>
					</tr>
				</table>
			</form>
			<div style="margin:10px auto 10px 29px;">
				<!--没有批量修改续约和解约的协议，所以暂时先去除批量-->
				<!--<button id="btnJy" class="btn btn-info" type="button">解约</button>-->
				<!--<button id="btnXy" class="btn btn-info" type="button">续约</button>-->
				<button id="btnZj" class="btn btn-info" type="button">转介</button>
				<!--<button onclick="doTimeTask()" class="btn btn-info" type="button">执行定时任务方法</button>-->
				<!-- <button id="btnBgfwb" class="btn btn-info" type="button">变更服务包</button> -->
				<!-- <button id="btnDy" class="btn btn-info" type="button">打印</button> -->
			</div>
	</div>
	<div region="center" style="height:150px;border:0">
		<table id="dgForm"></table>
	</div>
		<!-- <div class="easyui-layout" style="border: none;">
			<div region="center" style="border: none;">
			</div>
		</div> -->
			
				<!-- <div>
					<span>姓名:</span>
							<input id="XM" name="XM" class="form-control" type="text">
							<input id="QYZT" name="QYZT" value="0" type="hidden">		
							
							<span> 证件号码:</span>
							<input id="ZJHM" name="ZJHM" class="form-control" type="text">
							
							<span>人群分类：</span>
							<select id="RQFL" name="RQFL" class="form-control">
								<option value="">请选择</option>
								<option value="LNR">老年人</option>
								<option value="YCF">孕产妇</option>
								<option value="ET">儿童</option>
								<option value="CJR">残疾人</option>
								<option value="GXY">高血压</option>
								<option value="TNB">糖尿病</option>
								<option value="JHB">结核病</option>
								<option value="NCZ">脑卒中</option>
								<option value="SDJT">失独家庭</option>
							</select>
				</div>
				<div>
					<span>签约时间：</span>
                      <input id="QYKSSJ" name="QYKSSJ" style="height:30px;" class="input-text laydate-icon dataField" onclick="laydate()" />
                      -
                      <input id="QYJSSJ" name="QYJSSJ" style="height:30px;" class="input-text laydate-icon dataField" onclick="laydate()" placeholder=""/>
				
					<span>签约服务包：</span>
					<select id="FWBID" name="FWBID" class="form-control">
						<option value="">请选择</option>
						<option value="01">基础包</option>
						<option value="02">增强包</option>
					</select>
								
					<button id="btnQuery" class="btn btn-info" type="button" onclick="queryHandler()">查询</button>
				</div>
				<div style="margin-top:10px;">
					<button id="btnExport" class="btn btn-info" type="button">导出</button>
					<button id="btnJy" class="btn btn-info" type="button">解约</button>
					<button id="btnXy" class="btn btn-info" type="button">续约</button>
					<button id="btnZj" class="btn btn-info" type="button">转介</button>
					<button id="btnBgfwb" class="btn btn-info" type="button">变更服务包</button>
					<button id="btnDy" class="btn btn-info" type="button">打印</button>
				
				</div> -->
		<!-- </div>
		<div region="center" border="false">
			<table id="dgForm"></table>
		</div>	
	</div>
	
	<form action="downTdxxToExcel" method="post" enctype="multipart/form-data" id="downTdxxForm" style="display:none">
		<input id="downTdmc" name="TDMC" type="hidden"/>
		<input id="downShzt" name="SHZT" type="hidden"/>
	</form> -->

</body>
<!-- --> 
<script type="text/html" id="tableToolBar">
<a class="detail tableToolBarBtn" href="javascript:void(0)" title="详细">详细</a>
</script>

<script type="text/html" id="zjToolBar">
<textarea class="layui-layer-input"></textarea>
<select class="layui-layer-select"></select>
</script>
</html>
